//this file define different lockers for strategy locker
//andycai.sc@gmail.com

#ifndef GLOCKER_H
#define GLOCKER_H

#include "GParallel/GMutex.h"

//strategy locker interface
//it can use in single thread program for effictive
class GLocker
{
public:
    GLocker() {}
    virtual ~GLocker() {}

    virtual void lock() {}
    virtual void unlock() {}
};

//Mutex locker
class GMutexLocker : public GLocker
{
public:
    GMutexLocker() {}
    ~GMutexLocker() {}

    void lock()
    {
        m_mu.lock();
    }

    void unlock()
    {
        m_mu.unlock();
    }

private:
    GMutex m_mu;
};

//Scoped locker
class GScopedLocker
{
public:
    GScopedLocker(GLocker& locker) : m_locker(locker)
    {
        m_locker.lock();
    }

    ~GScopedLocker()
    {
        m_locker.unlock();
    }

private:
    GLocker& m_locker;
};

#endif // GLOCKER_H
